Socket
Socket
Sign inDemoInstall

@types/hapi__joi

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/hapi__joi

TypeScript definitions for @hapi/joi


Version published
Weekly downloads
288K
increased by5.54%
Maintainers
1
Weekly downloads
 
Created

What is @types/hapi__joi?

@types/hapi__joi is a TypeScript type definition package for the Joi library, which is used for data validation. It provides type definitions to ensure type safety and better development experience when using Joi in TypeScript projects.

What are @types/hapi__joi's main functionalities?

Basic Validation

This feature allows you to define a schema for basic string validation, specifying minimum and maximum length, and whether the field is required.

const Joi = require('@hapi/joi');

const schema = Joi.string().min(3).max(30).required();

const result = schema.validate('example');
console.log(result);

Object Validation

This feature allows you to define a schema for validating objects with various properties, including strings, numbers, and custom patterns.

const Joi = require('@hapi/joi');

const schema = Joi.object({
  username: Joi.string().alphanum().min(3).max(30).required(),
  password: Joi.string().pattern(new RegExp('^[a-zA-Z0-9]{3,30}$')),
  birth_year: Joi.number().integer().min(1900).max(2013)
});

const result = schema.validate({ username: 'abc', birth_year: 1994 });
console.log(result);

Array Validation

This feature allows you to define a schema for validating arrays, specifying the allowed values for the array items.

const Joi = require('@hapi/joi');

const schema = Joi.array().items(Joi.string().valid('a', 'b', 'c'));

const result = schema.validate(['a', 'b']);
console.log(result);

Custom Validation

This feature allows you to define custom validation logic using a custom function.

const Joi = require('@hapi/joi');

const schema = Joi.string().custom((value, helpers) => {
  if (value !== 'custom') {
    return helpers.error('any.invalid');
  }
  return value;
});

const result = schema.validate('custom');
console.log(result);

Other packages similar to @types/hapi__joi

FAQs

Package last updated on 21 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc